import Vue from 'vue'
import VueRouter from 'vue-router'
import InjectionRouterView from "@/utils/InjectionRouterView";
import {
    Login
} from '@/views';
import {AdminLayout} from '@/layout';
import {
    AbroadBusiness,
    AdditionalBasic,
    ItemOfExpenditure,
    PurchaseAdjustment,
    IndexReduction,
    NoProcurementAdjustment,
    ProjectAdjustment,
    UnitAdjustment,
    FunctionAdjustment,
    EconomicAdjustment,
    SystemSettings,
    ThreePublicFunds
} from "@/views/admin";
import RunTheHallOnceGuide from "@/views/home/components/RunTheHallOnceGuide";

Vue.use(VueRouter);

export const initializationRoutes = [
    {
        path: '/user',
        name: 'user',
        component: InjectionRouterView,
        redirect: '/user/login',
        children: [
            {
                name: 'login',
                path: '/user/login',
                component: Login
            }
        ]
    },
    {
        path: '/financial/guide',
        name: 'RunTheHallOnceGuide',
        component: RunTheHallOnceGuide
    },
    {
        path: '/admin/append',
        component: AdminLayout,
        meta: {
            title: '后台配置'
        },
        redirect: '/admin/append/additional',
        children: [
            {
                meta: {
                    title: '因公出国'
                },
                path: '/wmmno/chums/ozfir',
                component: AbroadBusiness
            },
            {
                meta: {
                    title: '基本支出'
                },
                path: '/admin/append/additional',
                component: AdditionalBasic
            },
            {
                meta: {
                    title: '项目支出指标申请'
                },
                path: '/admin/append/expenditure',
                component: ItemOfExpenditure
            },
        ]
    },
    {
        path: '/admin/index',
        component: AdminLayout,
        meta: {
            title: '后台配置'
        },
        redirect: '/admin/index/reduction',
        children: [
            {
                meta: {
                    title: '指标核减'
                },
                path: '/admin/index/reduction',
                component: IndexReduction
            },
        ]
    },
    {
        path: '/admin/adjustment',
        component: AdminLayout,
        meta: {
            title: '后台配置'
        },
        redirect: '/admin/adjustment/purchase',
        children: [
            {
                meta: {
                    title: '采购调整非采购'
                },
                path: '/admin/adjustment/purchase',
                component: PurchaseAdjustment
            },
            {
                path: '/admin/adjustment/no',
                component: NoProcurementAdjustment,
                meta: {
                    title: '非采购调整采购',
                }
            },
            {
                path: '/admin/adjustment/project',
                component: ProjectAdjustment,
                meta: {
                    title: '项目调整',
                }
            },
            {
                path: '/admin/adjustment/unit',
                component: UnitAdjustment,
                meta: {
                    title: '单位调整',
                }
            },
            {
                path: '/admin/adjustment/function',
                component: FunctionAdjustment,
                meta: {
                    title: '功能科目调整',
                }
            },
            {
                path: '/admin/adjustment/economic',
                component: EconomicAdjustment,
                meta: {
                    title: '经济科目调整',
                }
            },
        ]
    },
    {
        path: '/admin/system',
        component: AdminLayout,
        meta: {
            title: '系统设置'
        },
        redirect: '/admin/system/settings',
        children: [
            {
                meta: {
                    title: '系统设置'
                },
                path: '/admin/system/settings',
                component: SystemSettings
            },
        ]
    },
    {
        path: '/admin/public',
        component: AdminLayout,
        meta: {
            title: '三公经费'
        },
        redirect: '/admin/public/budget',
        children: [
            {
                meta: {
                    title: '预算表'
                },
                path: '/admin/public/budget',
                component: ThreePublicFunds
            },
        ]
    },
];

export const errorRouter = [
    {
        path: '*',
        name: 'error',
        component: () => import('@/views/404/Error'),
    }
]
const VueRouterPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(to) {
    return VueRouterPush.call(this, to).catch((err) => err);
}
const createRouter = () => new VueRouter({
    base: process.env.BASE_URL,
    routes: initializationRoutes
});

const router = createRouter();

export default router;
